<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="../../common/import.jsp"%>
<html>
<head>
<title></title>
   <style type="text/css">
      table.grid_layout th {
		    padding: 2px 0;
		    width: 80px;
		    text-align: right;
		    vertical-align: middle;
	  }
	  table.grid_layout td {
		    padding: 2px 0;
		    text-align: left;
		    vertical-align: middle;
	  }
   </style>
   <script src="${ctx}/resources/js/jquery.validate.min.js" type="text/javascript"></script>
   <script type="text/javascript">
	   $(function(){
		   $("#formTable").validate({
			   onsubmit: true, // 是否在提交时验证 
			   onfocusout: false, // 是否在获取焦点时验证 
			   validClass: 'checked',
			   rules: {
				   oldPassWord: {
						required: true,
						minlength: 6,
						maxlength: 10
					},
					passWord: {
						required: true,
						minlength: 6,
						maxlength: 10
					},
					repeatPassWord: {
						required: true,
						minlength: 6,
						maxlength: 10,
						equalTo: "#passWord"
					}
				},
				messages: {
					oldPassWord: {
						required: "请输入旧密码",
						minlength: "密码长度不能小于{0}",
						maxlength: "密码长度不能大于{0}"
					},
					passWord: {
						required: "请输入新密码",
						minlength: "密码长度不能小于{0}",
						maxlength: "密码长度不能大于{0}"
					},
					repeatPassWord: {
						required: "请重复输入新密码",
						minlength: "密码长度不能小于{0}",
						maxlength: "密码长度不能大于{0}",
						equalTo: "密码不一致!"
					}
				},
				success:function(label){
					label.addClass("checked").html("&nbsp;");
				},
				submitHandler: function(form) {
					$.blockUI();
					$.ajax({
		    			  url: "${ctx}/sys/user/changePwd.do",   // 提交的页面
		    		      data: $('#formTable').serialize(), // 从表单中获取数据
		    		      type: "POST",
		    		      success: function(data) {
		    		    	  $.unblockUI();
		    		    	   if(data.success==true){
		    		        		$.messager.alert('温馨提示', '修改成功,请重新登录!', 'info', function(){
		    		        			parent.location.replace("${ctx}/toLogin.do");
		    		        		});
		    		        	}else{
		    		        		parent.showFailAlert(data.msg)
		    		        	}
		    		      },
		    		      error: function(xhr) {
		    		    	  $.unblockUI();
		    		    	  showFailAlert2(xhr);
		    		      }
		    		  })
				}
			});
	   })
	   function save(){
		   $("#formTable").submit();
		   //document.forms["formTable"].submit();
	   }
       
   </script>
</head>
<body>
	<div class="easyui-layout" region="center" style="text-align: right;" fit="true">
		<div region="center" border="false" style="padding-top: 10px; padding-left: 30px; text-align: left; background: #fff; border: 1px solid #ccc;">
			<form id="formTable" method="post" >
				<input type="hidden" name="id" value="${user.id}"/>
				<table border="0" class="grid_layout" cellpadding="0" cellspacing="0">
					<tr>
						<th>&nbsp;&nbsp;用户名：</th>
						<td>
						${user.userName}
						</td>
					</tr>
					<tr>
						<th><span style="color: red;">*</span>旧密码：</th>
						<td>
						<input id="oldPassWord" name="oldPassWord" type="password" />
						</td>
					</tr>
					<tr>
						<th><span style="color: red;">*</span>新密码：</th>
						<td>
						<input id="passWord" name="passWord" type="password" />
						</td>
					</tr>
					<tr>
						<th><span style="color: red;">*</span>重复新密码：</th>
						<td><input id="repeatPassWord" name="repeatPassWord" type="password" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div region="south" border="false" style="text-align: right; padding: 5px 5px 5px 0;">
			<a class="easyui-linkbutton" iconcls="icon-ok" href="javascript:void(0)" onclick="save();">保存</a>
			<a class="easyui-linkbutton" iconcls="icon-cancel" href="javascript:void(0)" onclick="parent.closeWindow();">取消</a>
		</div>
	</div>
</body>
</html>
